require.config({
	paths : {
		"jquery" : "jquery",
		"cookie" : "cookie",
		"common" : "common"
	}
})

require(["jquery","cookie","common"],function($,cookie,common){
	$("#header").load("head.html",function(){common.fn();});
	$("#footer").load("foot.html",function(){common.fn();});
	
 	
 	//获取cookie中的用户信息
	var $users = getCookie("registerUsers") ? getCookie("registerUsers") : "";
	//将字符串转为对象
	$users = convertStrToObj($users);
	/*重置内容*/
 	var $arr = [0,0,0,0,0,0];
 	$(".regist_name input").val("");
 	$(".regist_password input").val("");
 	$(".regist_verify input").val("");
 	$(".regist_email input").val("");
 	$(".regist_qq input").val("");
 	$(".regist_name input").blur(function(){/*名字*/
 		if($(".regist_name input").val() != ""){
 			if((/^[\u4e00-\u9fa5\w]{4,}$/g).test($(".regist_name input").val())){
 				if($(".regist_name input").val() in $users){ //判断usn属性是否在users对象中。
					$arr[0] = 2;
 					$(".regist_name p i").removeClass("icon-017duihaoyuanxing").addClass("icon-gantanhao-copy").css("color","#b14c49");								
 					$(".regist_name p u").text("用户名已存在");
 					$(".regist_name p").css("display","block");
				}else{
					$arr[0] = 1;
	 				$(".regist_name p i").removeClass("icon-gantanhao-copy").addClass("icon-017duihaoyuanxing").css("color","#81a363");
	 				$(".regist_name p u").text("该登陆账户可用");
	 				$(".regist_name p").css("display","block");
				}
 				
 			}else{
 				$arr[0] = 2;
 				$(".regist_name p i").removeClass("icon-017duihaoyuanxing").addClass("icon-gantanhao-copy").css("color","#b14c49");								
 				$(".regist_name p u").text("登录账号最少4个字符");
 				$(".regist_name p").css("display","block");
 			}
 		}else{
 			$arr[0] = 0;
 			$(".regist_name p").css("display","none");
 		}
 	});
 	$(".regist_password input").blur(function(){/*密码*/
 		if($(".regist_password input").val() != ""){
 			if((/^[0-9A-Za-z]{6,20}$/g).test($(".regist_password input").val())){
 				$arr[1] = 1;
 				$(".regist_password p").css("display","none");
 			}else{
 				$arr[1] = 2;
 				$(".regist_password p i").removeClass("icon-017duihaoyuanxing").addClass("icon-gantanhao-copy").css("color","#b14c49");
 				$(".regist_password p u").text("输入不正确，最少6个字符");
 				$(".regist_password p").css("display","block");
 			}
 		}else{
 			$arr[1] = 0;
 			$(".regist_password p").css("display","none");
 		}
 	});
 	$(".regist_verify input").blur(function(){/*确认密码*/
 		if($(".regist_verify input").val() != ""){
 			if($(".regist_password input").val() == $(".regist_verify input").val()){
 				$arr[2] = 1;
 				$(".regist_verify p").css("display","none");
 			}else{
 				$arr[2] = 2;
 				$(".regist_verify p i").removeClass("icon-017duihaoyuanxing").addClass("icon-gantanhao-copy").css("color","#b14c49");
 				$(".regist_verify p u").text("密码与确认密码不相符，请重新填写");
 				$(".regist_verify p").css("display","block");
 			}
 		}else{
 			$arr[2] = 0;
 			$(".regist_verify p").css("display","none");
 		}
 	});
 	$(".regist_email input").blur(function(){/*email*/
 		if($(".regist_email input").val() != ""){
 			if((/^\w+@\w+.\w{2,3}(.\w{2,3})*$/g).test($(".regist_email input").val())){
 				$arr[3] = 1;
 				$(".regist_email p").css("display","none");
 			}else{
 				$arr[3] = 2;
 				$(".regist_email p i").removeClass("icon-017duihaoyuanxing").addClass("icon-gantanhao-copy").css("color","#b14c49");
 				$(".regist_email p u").text("Email格式有误，请重新输入");
 				$(".regist_email p").css("display","block");
 			}
 		}else{
 			$arr[3] = 0;
 			$(".regist_email p").css("display","none");
 		}
 	});
 	$(".regist_qq input").blur(function(){/*QQ*/
 		if($(".regist_qq input").val() != ""){
 			if((/^[0-9]{5,10}$/g).test($(".regist_qq input").val())){
 				$arr[4] = 1;
 				$(".regist_qq p").css("display","none");
 			}else{
 				$arr[4] = 0;
 				$(".regist_qq p i").removeClass("icon-017duihaoyuanxing").addClass("icon-gantanhao-copy").css("color","#b14c49");
 				$(".regist_qq p u").text("请输入数值");
 				$(".regist_qq p").css("display","block");
 			}
 		}else{
 			$arr[4] = 0;
 			$(".regist_qq p").css("display","none");
 		}
 	});
 	
 	$(".regist_sub input").click(function(){/*提交验证*/
 		if($(".regist_policy input").is(":checked")){/*是否同意协议*/
 			$arr[5] = 1;
 			$(".regist_policy p").css("display","none");
 			var $num = $arr[0] * $arr[1] * $arr[2] * $arr[3] * $arr[5];
	 		if($num == 1){
	 			var restart = confirm("确认提交");
				if(restart){
					var pass;
					if($arr[4] = 0){
						pass = [$(".regist_password input").val(),$(".regist_email input").val(),""]
					}else{
						pass = [$(".regist_password input").val(),$(".regist_email input").val(),$(".regist_qq input").val()]
					}
					$users[$(".regist_name input").val()] = pass;
					//设置用户信息cookie
					setCookie("registerUsers",convertObjToStr($users),7);
					setCookie("users_" + $(".regist_name input").val(),"");
					console.log(decodeURIComponent(document.cookie));
					alert("注册成功！")
				}
	 		}else if($num == 0){
	 			alert("输入未完成！")
	 		}else{
	 			alert("输入有误，请重新输入！")
	 		}
 		}else{
 			$arr[5] = 2;
			$(".regist_policy p i").removeClass("icon-017duihaoyuanxing").addClass("icon-gantanhao-copy").css("color","#b14c49");
			$(".regist_policy p u").text("请选择同意");
			$(".regist_policy p").css("display","block");
 		}
 	});
})
